package com.example.securitydemo.controller;

import com.aaa.entity.TabRole;
import com.aaa.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.securitydemo.service.ITabRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 于永利
 * @since 2023-07-14
 */
@RestController
@RequestMapping("/tab-role")
public class TabRoleController {
    @Resource
    private ITabRoleService roleService;


    @PostMapping
    public Result addRoleAndRoleMenu(TabRole roleData,String menuids){
        roleService.addRoleAndRoleMenu(roleData,menuids);
        return new Result(200,"成功",null);

    }

    @PutMapping
    public Result updRoleAndRoleMenu(TabRole roleData,String menuids){
        roleService.updRoleAndRoleMenu(roleData,menuids);
        return new Result(200,"成功",null);

    }

        @GetMapping
    public Result getAll(TabRole tabRole){
            QueryWrapper queryWrapper = new QueryWrapper();
            if(StringUtils.isNotBlank(tabRole.getRname())) {
                queryWrapper.eq("rname", tabRole.getRname());
            }
            List list = roleService.list(queryWrapper);
            return new Result(200,"成功",list);

    }

}
